package showtime.framework.utils
{
	import flash.utils.describeType;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	
	/** 
	 * @project showtime
	 * @author yinhao
	 * @date 2011-5-24
	 *
	 */
	
	public final class ClassUtility
	{
		private static const PACKAGE_CLASS_SEPARATOR:String = "::";
		
		
		public function ClassUtility()
		{
		}
		
		/**
		 * Get the <code>String</code> name of any <code>Object</code>.
		 * 
		 * @param	target		The <code>Object</code> object in question.
		 * @param	simple	Returns only the class name, not the package or packages.
		 * 
		 * @return	The name of the <code>Class</code> as a <code>String</code> object.
		 */
		static public function getClassName(target:Object,simple:Boolean=false):String
		{
			var result:String = getQualifiedClassName(target);
			
			result = result.replace("::",".");
			
			if(simple)
			{
				result = result.substr(result.lastIndexOf(".") + 1);
			}
			
			return result;
		};
		
		/**
		 * Look up a <code>Class</code> object by its string name.
		 * 
		 * @param	Name	The <code>String</code> name of the <code>Class</code> you are interested in.
		 * 
		 * @return	A <code>Class</code> object.
		 */
		static public function getClass(name:String):Class
		{
			return getDefinitionByName(name) as Class;
		}
		
		static public function isInterface(clazz:Class):Boolean
		{
			return (clazz === Object) ? false : (describeType(clazz).factory.extendsClass.length() == 0);
		}
		
	}
}